#!/usr/local/bin/python3
# -*- coding:utf8 -*-
# Author Aaron 
# 2017-04-12 23:22:45
import RPi.GPIO as GPIO
import time

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
pin = 7
pout = 11
GPIO.setup(pout, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(pin, GPIO.IN)
time.sleep(2)
def getDistance():
    GPIO.output(pout, GPIO.HIGH)
    time.sleep(0.00015)
    GPIO.output(pout, GPIO.LOW)

    while not GPIO.input(pin):
        pass
    start = time.time()
    while GPIO.input(pin):
        pass
    end = time.time()
    dis = (end - start) * 340 * 100 / 2
    print("开始:",str(start),"     结束:"+str(end))
    print("距离:", dis)



while True:
    getDistance()
    time.sleep(1)
GPIO.cleanup()
